home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / DIZZY / SRC / MACUTIL.C < prev    next >
C/C++ Source or Header  |  1991-10-03  |  3KB  |  156 lines

  1. #include "dizzy.h"
  2.  
  3. #ifdef    MACINTOSH
  4. /*    PictBit reads a picture resource, creates
  5. >>    a large enough bitmap and draws the picture
  6. >>    into it. The Bits bitmap is supplied to the
  7. >>    routine. Space for the actual bits is reserved
  8. >>    with NewPtr. Be sure to deallocate it once
  9. >>    it is no longer needed!
  10. >>
  11. >>    No error checking is made.
  12. */
  13. void    PictBit(Bits,PictId)
  14. BitMap    *Bits;
  15. int     PictId;
  16. {
  17.     GrafPort    AnyPort;
  18.     GrafPtr     SavedPort;
  19.     PicHandle    ThePic;
  20.     Rect        TempRect;
  21.     long        RAMNeeded;
  22.     
  23.     GetPort(&SavedPort);
  24.     OpenPort(&AnyPort);
  25.     
  26.     ThePic=(PicHandle)GetResource('PICT',PictId);
  27.     TempRect=(*ThePic)->picFrame;
  28.  
  29.     OffsetRect(&TempRect,-TempRect.left,-TempRect.top);
  30.     Bits->bounds=TempRect;
  31.  
  32.     Bits->rowBytes=((TempRect.right + 15) >> 4) << 1;    /*    Round to word boundary    */
  33.     RAMNeeded=Bits->rowBytes*(long)TempRect.bottom;     /*    Calculate RAM for bits    */
  34.     Bits->baseAddr=NewPtr(RAMNeeded);
  35.     
  36.     SetPortBits(Bits);
  37.     AnyPort.portRect=TempRect;
  38.     RectRgn(AnyPort.visRgn,&TempRect);
  39.     RectRgn(AnyPort.clipRgn,&TempRect);
  40.  
  41.     EraseRect(&TempRect);
  42.     DrawPicture(ThePic,&TempRect);
  43.  
  44.     ReleaseResource(ThePic);
  45.     ClosePort(&AnyPort);
  46.     SetPort(SavedPort);
  47. }
  48.  
  49. /*
  50. >>    Gets the mouse position while in a tracking loop.
  51. >>    Returns true when the mouse button comes up.
  52. */
  53.  
  54. int GetMouseTrackEvent(pt)
  55. Point    *pt;
  56. {
  57.     int     r=0;
  58.     
  59.     r=GetNextEvent(mUpMask+mDownMask,&MyEvent);
  60.     *pt=MyEvent.where;
  61.     GlobalToLocal(pt);
  62.     
  63.     if(r)    r=(MyEvent.what==mouseUp);
  64.     return !r;
  65. }
  66.  
  67. void    GetMouseDownPoint(pt)
  68. Point    *pt;
  69. {
  70.     *pt=MyEvent.where;
  71.     GlobalToLocal(pt);
  72. }
  73.  
  74. void    DoInits()
  75. {
  76.     char    StackSpace[32767];
  77.  
  78.     InitGraf(&thePort);
  79.     InitCursor();
  80.     InitFonts();
  81.     InitWindows();
  82.     InitMenus();
  83.     TEInit();
  84.     InitDialogs(0L);
  85.     MaxApplZone();
  86. }
  87.  
  88. int GetDownButton()
  89. {
  90.     int     WhichButton=0;
  91.  
  92.     if(MyEvent.modifiers & optionKey)
  93.     {    WhichButton=1;
  94.     }
  95.     else if(MyEvent.modifiers & cmdKey)
  96.     {    WhichButton=2;
  97.     }
  98.     
  99.     return    WhichButton;
  100. }
  101.  
  102. void    DoHandScroller()
  103. {
  104.     BitMap        EditBuffer;
  105.     GrafPort    TempClipper;
  106.     Rect        dest;
  107.     Point        StartSpot,OldSpot,MousePoint;
  108.     RgnHandle    Eraser;
  109.     int         downflag;
  110.  
  111.     ClipEditArea();
  112.     SetCursor(*GetCursor(128));
  113.     
  114.     EditBuffer.bounds=EditClipper;
  115.     EditBuffer.rowBytes=((EditClipper.right-EditClipper.left + 15) >> 4) << 1;
  116.     EditBuffer.baseAddr=NewPtrClear(EditBuffer.rowBytes*(long)(EditClipper.bottom-EditClipper.top));
  117.     OpenPort(&TempClipper);
  118.     SetPort(&TempClipper);
  119.     SetPortBits(&EditBuffer);
  120.     RectRgn(TempClipper.visRgn,&EditBuffer.bounds);
  121.     UpdateSim();
  122.     ClosePort(&TempClipper);
  123.     SetPort(MyWind);
  124.  
  125.     GetMouseDownPoint(&StartSpot);
  126.     OldSpot=StartSpot;
  127.  
  128.     Eraser=NewRgn();
  129.     do
  130.     {    downflag=GetMouseTrackEvent(&MousePoint);
  131.         
  132.         if(MousePoint.h!=OldSpot.h || MousePoint.v != OldSpot.v)
  133.         {    dest=EditClipper;
  134.             OldSpot=MousePoint;
  135.             OffsetRect(&dest,OldSpot.h-StartSpot.h,OldSpot.v-StartSpot.v);
  136.             CopyBits(&EditBuffer,&MyWind->portBits,&EditBuffer.bounds,&dest,srcCopy,0L);
  137.  
  138.             OpenRgn();
  139.             FrameRect(&EditClipper);
  140.             FrameRect(&dest);
  141.             CloseRgn(Eraser);
  142.             EraseRgn(Eraser);
  143.         }
  144.     }    while(downflag);
  145.     
  146.     CurHeader->XOrig-=OldSpot.h-StartSpot.h;
  147.     CurHeader->YOrig-=OldSpot.v-StartSpot.v;
  148.     
  149.     InvalRgn(Eraser);
  150.     DisposeRgn(Eraser);
  151.     DisposPtr(EditBuffer.baseAddr);
  152.     InitCursor();
  153.     RestoreClipping();
  154. }
  155. #endif
  156.